/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.ce.commands.systemacc;

import com.bionic.ce.beans.Systemacc;
import com.bionic.ce.businesslogic.SystemAccService;
import com.bionic.ce.commands.ICommand;
import com.bionic.ce.manager.Config;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author MAXIM
 */
public class CommandDeleteSystemAcc implements ICommand {

    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String page = null;
        Integer systemAccid = ((Systemacc)request.getSession().getAttribute("systemacc")).getSystemaccId();
        Double amount = ((Systemacc)request.getSession().getAttribute("systemacc")).getAmount();
        if (amount==0){
        SystemAccService.deleteCurrentSystemacc(systemAccid);
        request.getSession().removeAttribute("systemacc");
        (new CommandGoToSystemAccountInfo()).execute(request, response);
        page = Config.getInstance().getProperty(Config.GOTOSYSTEMACCAOUNTSINFO);}
        else{        
        request.setAttribute("systemaccdeleteerror", "You can`t delete acount while there is money");
        page = Config.getInstance().getProperty(Config.GOTOSYSTEMACCINFO);}
        
        
        return page;

    }
}